package com.stx.friends.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.stx.friends.service.BloggerService;
import com.stx.friends.vo.BloggerVo;
//ActionSupport~~~~~~Struts提供的父类
public class BloggerAction extends ActionSupport{
	//将BloggerService定义为一个私有属性service
	private BloggerService service;
	//从网页中获取信息
	HttpServletRequest request=ServletActionContext.getRequest();
	//博客信息列表
		private List<BloggerVo> bloggerList =new ArrayList<BloggerVo>();
		//定义对象博客查询条件
		private BloggerVo criteria =null;
		//博客内容
		private BloggerVo blogger=null;
		//博文ID
		private String bid=null;
		//全部博客
		public String list(){
			bloggerList =service.list(new BloggerVo());
			return "success";
	}
		//得到我的博客
		public String listByUid(){
			//将页面中的WrxUid传给字符串变量wrxUid
			String wrxUid=request.getParameter("wrxUid");			
			bloggerList=service.listByUid(wrxUid);
			return SUCCESS;
		}
		//得到收藏博客的所有内容
		public String listLike(){
			bloggerList =service.listLike(new BloggerVo());
			return "success";
	}
		//删除博客
		public String del(){
			bid=request.getParameter("bid");
			service.delBlogger(bid);
			return "success";
		}
		//添加博客
		public String add(){
			service.addBlogger(blogger);
			return "list";
		}
		//修改博客
		public String edit(){
			bid=request.getParameter("bid");
			blogger=this.service.getBloggerById(bid);
			System.out.println(blogger.getTitle());
			return SUCCESS;
		}
		//更新
		public String update(){
			this.service.updateblogger(criteria);			
			System.out.println(criteria.getTitle());
			return SUCCESS;
			
		}
		//查看收藏博客
		public String like(){
			service.likeBlogger(request.getParameter("bid"));
			return "success";
		}
		//取消收藏博客
		public String unLike(){
			service.unLikeBlogger(request.getParameter("bid"));
			return "success";
		}
		//get、set方法-----------------------------------------------------
		public BloggerService getService() {
			return service;
		}
		public void setService(BloggerService service) {
			this.service = service;
		}
		public List<BloggerVo> getBloggerList() {
			return bloggerList;
		}
		public void setBloggerList(List<BloggerVo> bloggerList) {
			this.bloggerList = bloggerList;
		}
		public BloggerVo getCriteria() {
			return criteria;
		}
		public void setCriteria(BloggerVo criteria) {
			this.criteria = criteria;
		}
		public BloggerVo getBlogger() {
			return blogger;
		}
		public void setBlogger(BloggerVo blogger) {
			this.blogger = blogger;
		}
		public String getBid() {
			return bid;
		}
		public void setBid(String bid) {
			this.bid = bid;
		}
		
}
